-- 海星清远古
-- 无需增加重置图标位置的功能，虽然可以拖动，但只要开启就显示在屏幕中央

local ImageButton = require "widgets/imagebutton"
local Image = require "widgets/image"
local Widget = require "widgets/widget"
local t_util = require "libs/tableutil"
local e_util = require "libs/entutil"
local h_util = require "libs/hudutil"
local Text = require "widgets/text"
local TEMPLATES = require "widgets/redux/templates"

local SF = Class(Widget, function(self, data)
    Widget._ctor(self, "STARFISH")
    self:SetVAnchor(ANCHOR_BOTTOM)
    self:SetHAnchor(ANCHOR_LEFT)
    
    local screen_w, screen_h = TheSim:GetScreenSize()
    self:SetPosition(screen_w/2, screen_h/2)
    local bg_width = 300
    local bg_height = 400
    local f_atlas = resolvefilepath(CRAFTING_ATLAS)
    self.frame = self:AddChild(Widget("frame"))
    self.frame:SetHoverText(STRINGS.LMB.."可拖拽", {offset_y = 300, colour = UICOLOURS.GOLD, fontsize = 30})
    ---------- fill
    local fill = self.frame:AddChild(Image(f_atlas, "backing.tex"))
    fill:ScaleToSize(bg_width + 10, bg_height + 18)
    fill:SetTint(1,1,1,0.35)
    ---------- line
    local left = self.frame:AddChild(Image(f_atlas, "side.tex"))
    local right = self.frame:AddChild(Image(f_atlas, "side.tex"))
    local top = self.frame:AddChild(Image(f_atlas, "top.tex"))
    local bottom = self.frame:AddChild(Image(f_atlas, "bottom.tex"))
    local itemlist_split = self.frame:AddChild(Image(f_atlas, "horizontal_bar.tex"))
    local title = self.frame:AddChild(Text(HEADERFONT, 30, "生成点预测器", UICOLOURS.WHITE))
    -- debug
    -- self.left, self.right, self.top, self.bottom = left, right, top, bottom
    left:SetPosition(-bg_width / 2 - 6, 1)
    right:SetPosition(bg_width / 2 + 6, 1)
    top:SetPosition(0, bg_height / 2 + 10)
    bottom:SetPosition(0, -bg_height / 2 - 8)
    title:SetPosition(0, bg_height/2-8)

    left:ScaleToSize(-13, -(bg_height - 10))
    right:ScaleToSize(13, bg_height - 10)
    top:ScaleToSize(bg_width+22, 33)
    bottom:ScaleToSize(bg_width+22, 33)

    itemlist_split:SetPosition(0, bg_height/2-25)
    itemlist_split:ScaleToSize(bg_width, 15)

    local Btns = self:AddChild(Widget("btns"))
    Btns:SetPosition(0, bg_height/2-25)

    -- 探测按钮
    self.btn_tile = Btns:AddChild(TEMPLATES.StandardButton(function()
        self.btn_tile:SetText(self.btn_tile.value and "预测生成点" or "清理预测点")
        self.btn_tile.value = not self.btn_tile.value
        data.Tile(self, self.btn_tile.value)
    end, "预测生成点", {bg_width-50, 80}))
	self.btn_tile:SetPosition(0, -50)
    self.btn_tile:SetHoverText("扫描地皮并预测周围生物的刷新点\n 此功能仅限洞穴有用", {offset_y = 60, fontsize = 30})

    self.btn_record = Btns:AddChild(TEMPLATES.StandardButton(function()
        self.btn_record:SetText(self.btn_record.value and "回忆生成点" or "清理回忆点")
        self.btn_record.value = not self.btn_record.value
        data.Record(self, self.btn_record.value)
    end, "回忆生成点", {bg_width-50, 80}))
	self.btn_record:SetPosition(0, -140)
    self.btn_record:SetHoverText("读取玩家上次到来时的记忆，展示周围生物刷新点\n 此功能还显示蚁狮和赃物袋", {offset_y = 60, fontsize = 30})
    
    self.btn_deploy = Btns:AddChild(TEMPLATES.StandardButton(function()
        data.Deploy(self)
    end, "海星种植", {bg_width-50, 80}))
	self.btn_deploy:SetPosition(0, -230)
    self.btn_deploy:SetHoverText("寻找距离玩家最近的一个生成点,\n 然后种植海星", {offset_y = 60, fontsize = 30})
    
    self.btn_kill = Btns:AddChild(TEMPLATES.StandardButton(function()
        self:GetParent().hx_starfish = nil
        self:Kill()
    end, "关闭窗口", {bg_width-50, 80}))
	self.btn_kill:SetPosition(0, -320)
    self.btn_kill:SetHoverText("不需要我了吗？≧﹏≦", {offset_y = 60, fontsize = 30})
end)

-- function SF:B_start()
--     self.btn_tile:SetText()
-- end


h_util:ActivateUIDraggable(SF)
return SF